# Maintainer: taotieren <admin@taotieren.com>

pkgname=crm-git
pkgver=0.2.2.r5.g546eed8
pkgrel=1
pkgdesc="crm (Cargo registry manager)"
arch=($CARCH)
url="https://github.com/wtklbm/crm"
license=('MIT AND Apache-2.0')
provides=(${pkgname%-git})
conflicts=(${pkgname%-git})
replaces=()
depends=(
    gcc-libs
    glibc
)
makedepends=(
    git
    cargo
)
backup=()
options=('!lto' '!debug')
install=
source=("${pkgname%-git}::git+${url}.git")
sha256sums=('SKIP')

pkgver() {
    cd "${srcdir}/${pkgname%-git}/"
    git describe --long --tags | sed 's/v//g;s/\([^-]*-g\)/r\1/;s/-/./g'
}

prepare() {
    git -C "${srcdir}/${pkgname%-git}" clean -dfx
    cd "${srcdir}/${pkgname%-git}/"
    #     cargo fetch --locked --target "$(rustc -vV | sed -n 's/host: //p')"
    cargo fetch --target "$CARCH-unknown-linux-gnu"
}

build() {
    cd "${srcdir}/${pkgname%-git}/"

    export RUSTUP_TOOLCHAIN=stable
    export CARGO_TARGET_DIR=target

    cargo build --release --all-features
}

check() {
    cd "${srcdir}/${pkgname%-git}/"

    export RUSTUP_TOOLCHAIN=stable
    cargo test --all-features
}

package() {
    cd "${srcdir}/${pkgname%-git}/"

    export RUSTUP_TOOLCHAIN=stable

    cargo install --no-track --all-features --root "$pkgdir/usr/" --path .
    install -Dm0644 "LICENSE-MIT" -t "${pkgdir}/usr/share/licenses/${pkgname}/"
    install -Dm0644 "LICENSE-Apache-2.0" -t "${pkgdir}/usr/share/licenses/${pkgname}/"
}
